home *** CD-ROM | disk | FTP | other *** search
- Path: menkar.cs.utk.edu!doolin
- From: doolin@menkar.cs.utk.edu (David Doolin)
- Newsgroups: comp.lang.c
- Subject: why empty dlist?
- Date: 29 Feb 1996 20:13:21 GMT
- Organization: University of Tennessee Computer Science
- Distribution: world
- Message-ID: <4h51d1INNcrr@CS.UTK.EDU>
- Reply-To: doolin@cs.utk.edu
- NNTP-Posting-Host: menkar.cs.utk.edu
-
- Why might the following piece of code not work?
-
- 1 for (tmp = bedlist->flink; tmp != bedlist->blink; tmp = tmp->flink) {
- 2 headl = (Dlist) tmp->val;
- 3 headr = (Dlist) tmp->flink->val;
-
- Defs: Dlist points forward (flink), backwards (blink),
- and types void *val. tmp, bedlist, headl, and headr are
- all Dlist structures. bedlist consists of a doubly linked
- list where every node points to an identical doubly
- linked list, which points to some data. There is a head
- node on each list, with null value.
-
- bedlist_head<->Node1<->Node2<->...<->Node_last<->bedlist_head
- ^ ^ ^
- | | |
- headl headr etc.
- | |
- node1 node1
- | | <- these are doubly linked.
- ... ...
- | |
- last last
-
- The object is to construct a new list with combining Node1
- list with Node2 list. The merge proceeds nicely with the
- first loop, and the headr list increments as planned right
- down the bedlist, but the headl doesn't make it past the
- first loop. It merges on the first loop, then remains
- empty through the rest of it. Doesn't seg fault either.
- On the 2d loop,
- I know headl is empty after the assignment on line 2 because
- I checked it; it points to itself, i.e. empty.
-
- Am I missing something obvious here?
-
- Many thanks for any help,
- Dave Doolin
-
-
-